

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store;
using JTC.MiniCommerce.Store.Services.ShippingService;
using JTC.MiniCommerce.Store.Services.PaymentService;
using JTC.MiniCommerce.Store.Services.CouponService;
using SubSonic.Utilities;

namespace JTC.MiniCommerce.Web {
  public partial class checkout : System.Web.UI.Page {

    #region Constants

    private const string PAYPAL_PAYER_ID = "PayPalPayerId";
    private const string PAYPAL_TOKEN = "PayPalToken";

    #endregion
    
    #region Member Variables

    private Order order;
    
    #endregion
    
    #region Page Events

    /// <summary>
    /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event to initialize the page.
    /// </summary>
    /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
    protected override void OnInit(EventArgs e) {
      if(Master.SiteSettings.LoginRequirement == LoginRequirement.Checkout) {
        if(!User.Identity.IsAuthenticated) {
          Response.Redirect(string.Format("login.aspx?ReturnUrl={0}", Request.Url), true);
        }
      }

      PaymentService paymentService = new PaymentService();
      if(paymentService.PaymentServiceSettings.DefaultProvider == "PayPalStandardPaymentProvider") {
        Response.Redirect("~/paypalcheckout.aspx", true);
      }

      //Keep these here - the Accordion ViewState is funky and requires things to be set early
      Label lblBillingInformation = acCheckout.Panes[0].FindControl("lblBillingInformation") as Label;
      Label lblShippingInformation = acCheckout.Panes[1].FindControl("lblShippingInformation") as Label;
      Label lblShippingMethod = acCheckout.Panes[2].FindControl("lblShippingMethod") as Label;
      Label lblCouponInformation = acCheckout.Panes[3].FindControl("lblCouponInformation") as Label;
      Label lblPaymentInformation = acCheckout.Panes[4].FindControl("lblPaymentInformation") as Label;
      Label lblOrderReview = acCheckout.Panes[5].FindControl("lblOrderReview") as Label;
      LocalizationUtility.AddLabelText(lblBillingInformation);
      LocalizationUtility.AddLabelText(lblShippingInformation);
      LocalizationUtility.AddLabelText(lblShippingMethod);
      LocalizationUtility.AddLabelText(lblCouponInformation);
      LocalizationUtility.AddLabelText(lblPaymentInformation);
      LocalizationUtility.AddLabelText(lblOrderReview);

      //Keep these here - the Accordion ViewState is funky and requires things to be set early
      order = new OrderController().FetchOrder(WebUtility.GetUserName());

      SetBillToAddressDisplay();

      SetShipToAddressDisplay();

      SetShippingMethodDisplay();
      
      //SetCouponDisplay();

      if(!string.IsNullOrEmpty(order.PaymentMethod)) {
        if(order.PaymentMethod == "PayPal") {
          string token = Utility.GetParameter("token");
          if(!string.IsNullOrEmpty(token)) {
            pnlCreditCardInformation.Visible = false;
            pnlCreditCardInfo.Visible = false;
            lblCreditCardType.Text = order.PaymentMethod;
            ddlCreditCardType.SelectedValue = "4";
            PayPalPayer payPalPayer = OrderController.GetExpressCheckout(token);
            if(order.BillingAddress == null) {//Then they are coming in from the cart.aspx ExpressCheckout button
              //copy the PayPalPayer ShippingAddress and then flag it as a BillingAddress
              Address billingAddress = new Address(payPalPayer.ShippingAddress);
              billingAddress.AddressType = AddressType.BillingAddress;
              WebProfile.Current.AddressCollection.Add(billingAddress);
              WebProfile.Current.Save();
              order.BillToAddress = payPalPayer.ShippingAddress.ToXml();
            }
            if(!payPalPayer.ShippingAddress.Equals(order.ShippingAddress)) {
              WebProfile.Current.AddressCollection.Add(payPalPayer.ShippingAddress);
              WebProfile.Current.Save();
              order.ShipToAddress = payPalPayer.ShippingAddress.ToXml();
            }
            if(order.ExtendedProperties.ContainsKey(PAYPAL_PAYER_ID)) {
              order.ExtendedProperties.Remove(PAYPAL_PAYER_ID);
            }
            if(order.ExtendedProperties.ContainsKey(PAYPAL_TOKEN)) {
              order.ExtendedProperties.Remove(PAYPAL_TOKEN);
            }
            order.ExtendedProperties.Add(PAYPAL_PAYER_ID, payPalPayer.PayPalPayerId);
            order.ExtendedProperties.Add(PAYPAL_TOKEN, payPalPayer.PayPalToken);
            order.AdditionalProperties = order.ExtendedProperties.ToXml();
            order.Save(WebUtility.GetUserName());

            SetBillToAddressDisplay();

            SetShipToAddressDisplay();
          }
        }
      }
      base.OnInit(e);
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        //Set these early, so they can be overridden - they aren't used in production
        #if DEBUG
          if (!Page.IsPostBack) {
            if (order.PaymentMethod != "PayPal") {
              ddlCreditCardType.SelectedValue = "1";
              txtCreditCardNumber.Text = "4978368392614864";
              txtCreditCardSecurityNumber.Text = "027";
              int selectedMonth = (DateTime.UtcNow.Month + 1);
              ddlCreditCardExpirationMonth.SelectedValue = selectedMonth.ToString();
            }
          }
        #endif

        if (Master.SiteSettings.RequireSsl) {
          WebUtility.EnsureSsl();
        }
        if (order.OrderItemCollection.Count <= 0) {
          Response.Redirect("~/cart.aspx", true);
        }
        ShippingService shippingService = new ShippingService();
        if (!shippingService.ShippingServiceSettings.UseShipping) {
          acCheckout.Panes[1].Visible = false;
          acCheckout.Panes[2].Visible = false;
          pnlShippingAddressDisplayTitle.Visible = false;
          pnlShippingAddressDisplay.Visible = false;
          chkUseForShipping.Visible = false;
        }

        orderSummary.Order = order;

        LoadExpirationYearDropDown();
        LoadExpirationMonthDropDown();

        //this.btnProcessOrder.Attributes.Add("onclick", string.Format("this.value='{0}';this.disabled = true;" + Page.ClientScript.GetPostBackEventReference(this.btnProcessOrder, ""), LocalizationUtility.GetText("lblPleaseWait")));
        this.btnProcessOrder.Attributes.Add("onclick", "this.disabled = true;" + Page.ClientScript.GetPostBackEventReference(this.btnProcessOrder, ""));
        this.btnProcessOrder.Enabled = false;
        SetCheckoutProperties();
      }
      catch (Exception ex) {
        Logger.Error(typeof(checkout).Name + ".Page_Load", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the PreRender event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_PreRender(object sender, EventArgs e) {
      upDisplay.ProgressTemplate = new OrderProgressTemplate();
    }

    /// <summary>
    /// Handles the Click event of the btnBillingAddress control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnBillingAddress_Click(object sender, EventArgs e) {
      try {
        //First, get the BillingAddress squared away
        Address address = new Address();
        if(!billingAddress.NewAddressPanel.Visible) { //From the ddl
          Guid selectedAddress = new Guid(billingAddress.AddressList.SelectedValue);
          address = WebProfile.Current.AddressCollection.Find(delegate(Address addressToFind) {
            return addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.BillingAddress;
          });
        }
        else {
          if(!string.IsNullOrEmpty(billingAddress.AddressId)) { //They are editing an existing address
            Guid selectedAddress = new Guid(billingAddress.AddressId);
            address = WebProfile.Current.AddressCollection.Find(delegate(Address addressToFind) {
              return addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.BillingAddress;
            });
            if(address.AddressId != Guid.Empty) {
              //go ahead and remove it - we are just going to add it with the updated info
              WebProfile.Current.AddressCollection.Remove(address);
            }
          }
          //else {
          //  address.AddressId = Guid.NewGuid(); //new address, so set the id
          //}
          address.FirstName = billingAddress.FirstName;
          address.LastName = billingAddress.LastName;
          address.Phone = billingAddress.Phone;
          address.Email = billingAddress.Email;
          address.Address1 = billingAddress.Address1;
          address.Address2 = billingAddress.Address2;
          address.City = billingAddress.City;
          address.StateOrRegion = billingAddress.StateOrRegion;
          address.PostalCode = billingAddress.PostalCode;
          address.Country = billingAddress.Country;
          address.UserName = WebUtility.GetUserName();
          address.AddressType = AddressType.BillingAddress;
          WebProfile.Current.AddressCollection.Add(address);
          WebProfile.Current.Save();
          //set the id so we can get it to determine if it's an edit or not
          billingAddress.AddressId = address.AddressId.ToString();

        }

        order.BillToAddress = address.ToXml();
        order.Save(WebUtility.GetUserName());
        billingAddressDisplay.Address = address;
        billingAddressDisplay.DisplayAddress();

        //Second, check to see if we are using it for shipping as well
        if(chkUseForShipping.Checked) {
          if(billingAddress.NewAddressPanel.Visible) {
            shippingAddress.NewAddressPanel.Visible = true;
            //copy over the info
            shippingAddress.AddressId = billingAddress.AddressId;
            shippingAddress.FirstName = billingAddress.FirstName;
            shippingAddress.LastName = billingAddress.LastName;
            shippingAddress.Phone = billingAddress.Phone;
            shippingAddress.Email = billingAddress.Email;
            shippingAddress.Address1 = billingAddress.Address1;
            shippingAddress.Address2 = billingAddress.Address2;
            shippingAddress.City = billingAddress.City;
            shippingAddress.StateOrRegion = billingAddress.StateOrRegion;
            shippingAddress.PostalCode = billingAddress.PostalCode;
            shippingAddress.Country = billingAddress.Country;
          }
          //We need to see if its already in there as a ShippingAddress and if not, add it

          //First, look it up to see if it's already in the Shipping Address list

          //We keep the ID the same, just changing the AddressType, so search based on ID 
          //is ok because the lists are sorted by AddressType when loaded
          ListItem itsInThere = shippingAddress.AddressList.Items.FindByValue(address.AddressId.ToString());
          if(itsInThere == null) {//then add it
            Address shipAddress = new Address(address);
            shipAddress.AddressType = AddressType.ShippingAddress;
            WebProfile.Current.AddressCollection.Add(shipAddress);
            WebProfile.Current.Save();
            //now, reload the addresses
            shippingAddress.LoadAddresses();
          }
          //set the shipping address as selected
          shippingAddress.AddressList.ClearSelection();
          shippingAddress.AddressList.Items.FindByValue(address.AddressId.ToString()).Selected = true;

          //set the order shipping address
          order.ShipToAddress = address.ToXml();
          order.Save(WebUtility.GetUserName());
          shippingAddressDisplay.Address = address;
          shippingAddressDisplay.DisplayAddress();
          //Now get the shipping rates because we are skipping ahead
          GetShippingRates();
        }
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnBillingAddress_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the Click event of the btnShippingAddress control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnShippingAddress_Click(object sender, EventArgs e) {
      try {
        Address address = new Address();
        if(!shippingAddress.NewAddressPanel.Visible) {
          Guid selectedAddress = new Guid(shippingAddress.AddressList.SelectedValue);
          address = WebProfile.Current.AddressCollection.Find(delegate(Address addressToFind) {
            return addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.ShippingAddress;
          });
        }
        else {
          if(!string.IsNullOrEmpty(shippingAddress.AddressId)) { //They are editing an existing address
            Guid selectedAddress = new Guid(shippingAddress.AddressId);
            address = WebProfile.Current.AddressCollection.Find(delegate(Address addressToFind) {
              return addressToFind.AddressId == selectedAddress && addressToFind.AddressType == AddressType.ShippingAddress;
            });
            if(address.AddressId != Guid.Empty) {
              //go ahead and remove it - we are just going to add it with the updated info
              WebProfile.Current.AddressCollection.Remove(address);
            }
          }
          address.FirstName = shippingAddress.FirstName;
          address.LastName = shippingAddress.LastName;
          address.Phone = shippingAddress.Phone;
          address.Email = shippingAddress.Email;
          address.Address1 = shippingAddress.Address1;
          address.Address2 = shippingAddress.Address2;
          address.City = shippingAddress.City;
          address.StateOrRegion = shippingAddress.StateOrRegion;
          address.PostalCode = shippingAddress.PostalCode;
          address.Country = shippingAddress.Country;
          address.UserName = WebUtility.GetUserName();
          address.AddressType = AddressType.ShippingAddress;
          WebProfile.Current.AddressCollection.Add(address);
          WebProfile.Current.Save();
          //set the id so we can get it to determine if it's an edit or not
          shippingAddress.AddressId = address.AddressId.ToString();
        }
        order.ShipToAddress = address.ToXml();
        order.Save(WebUtility.GetUserName());
        shippingAddressDisplay.Address = address;
        shippingAddressDisplay.DisplayAddress();
        GetShippingRates();
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnShippingAddress_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the Click event of the btnShippingMethod control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnShippingMethod_Click(object sender, EventArgs e) {
      try {
        decimal shippingAmount = 0;
        decimal.TryParse(rblShippingOptions.SelectedValue, out shippingAmount);
        OrderController.SetShipping(WebUtility.GetUserName(), shippingAmount, rblShippingOptions.SelectedItem.Text);
        OrderController.CalculateTax(WebUtility.GetUserName());
        lblShippingMethodDisplay.Text = rblShippingOptions.SelectedItem.Text;
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnShippingMethod_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the Click event of the btnPaymentMethod control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnPaymentMethod_Click(object sender, EventArgs e) {
      try {
        //Loadup the cpe and validate the CC if possible
        int creditCardType = 0;
        int.TryParse(ddlCreditCardType.SelectedValue, out creditCardType);
        lblCreditCardType.Text = Enum.GetName(typeof(CreditCardType), creditCardType);
        CreditCardType cardType = (CreditCardType)Enum.Parse(typeof(CreditCardType), ddlCreditCardType.SelectedValue);

        if(cardType == CreditCardType.PayPal) {
          if(Page.Request["token"] == null) {
            pnlCreditCardInfo.Visible = false;
            order.PaymentMethod = CreditCardType.PayPal.ToString();
            order.Save(WebUtility.GetUserName());
            string returnUrl = Utility.GetSiteRoot() + "/checkout.aspx";
            string cancelUrl = Utility.GetSiteRoot() + "/default.aspx";
            string url = OrderController.SetExpressCheckout(order, returnUrl, cancelUrl, false);
            Response.Redirect(url, true);
          }
          else {
            //Don't do anything, they already have a token - came in through cart ExpressCheckout
          }
        }
        else {
          if(WebUtility.IsValidCardType(txtCreditCardNumber.Text.Trim(), cardType)) {
            int creditCardLength = txtCreditCardNumber.Text.Trim().Length;
            string creditCardDisplay = string.Empty;
            for(int i = 1;i <= txtCreditCardNumber.Text.Trim().Length - 4;i++) {
              creditCardDisplay += "X";
            }
            creditCardDisplay += txtCreditCardNumber.Text.Trim().Substring(txtCreditCardNumber.Text.Trim().Length - 4, 4);
            lblMaskedCreditCardNumber.Text = creditCardDisplay;
            int year = DateTime.UtcNow.Year;
            int.TryParse(ddlCreditCardExpirationYear.SelectedValue, out year);
            int month = DateTime.UtcNow.Month;
            int.TryParse(ddlCreditCardExpirationMonth.SelectedValue, out month);
            DateTime expirationDate = new DateTime(year, month, DateTime.DaysInMonth(year, month));
            lblExpirationDate.Text = StoreUtility.GetFormattedDate(expirationDate);
          }
          else {
            throw new InvalidOperationException("Credit card number does not validate.");
          }
        }
        this.btnProcessOrder.Enabled = true;
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnPaymentMethod_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the Click event of the btnCoupon control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnCoupon_Click(object sender, EventArgs e) {
      try {
        if(!string.IsNullOrEmpty(txtCouponCode.Text)) {
          CouponService couponService = new CouponService();
          couponService.ApplyCoupon(txtCouponCode.Text, order);
          lblCouponInformationDisplay.Text = StoreUtility.GetFormattedAmount(order.DiscountAmount, true);
        }
        else {
          lblCouponInformationDisplay.Text = StoreUtility.GetFormattedAmount(0.00M, true);
        }
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnCoupon_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Handles the Click event of the btnProcessOrder control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void btnProcessOrder_Click(object sender, EventArgs e) {
      try {
        Transaction transaction = null;
        order.CreditCardType = (CreditCardType)Enum.Parse(typeof(CreditCardType), ddlCreditCardType.SelectedValue);
        if(order.PaymentMethod == "PayPal") {
          transaction = OrderController.DoExpressCheckout(order, false, WebUtility.GetUserName());
        }
        else {
          order.CreditCardNumber = txtCreditCardNumber.Text;
          order.CreditCardSecurityNumber = txtCreditCardSecurityNumber.Text;
          order.CreditCardExpirationMonth = int.Parse(ddlCreditCardExpirationMonth.SelectedValue);
          order.CreditCardExpirationYear = int.Parse(ddlCreditCardExpirationYear.SelectedValue);
          transaction = OrderController.Charge(order, WebUtility.GetUserName());
        }
        Response.Redirect(string.Format("~/receipt.aspx?tid={0}", transaction.TransactionId), true);
      }
      catch(Exception ex) {
        Logger.Error(typeof(checkout).Name + ".btnProcessOrder_Click", ex);
        throw;
      }
    }

    /// <summary>
    /// Gets the formatted amount.
    /// </summary>
    /// <param name="pricePaid">The price paid.</param>
    /// <returns></returns>
    protected string GetFormattedAmount(string pricePaid) {
      return StoreUtility.GetFormattedAmount(pricePaid, true);
    }

    /// <summary>
    /// Toggles the credit card info.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void toggleCreditCardInfo(object sender, EventArgs e) {
      if(ddlCreditCardType.SelectedValue == "4") {
        pnlCreditCardInformation.Visible = false;
      }
      else {
        pnlCreditCardInformation.Visible = true;
      }
    }
    
    #endregion

    #region Private Methods

    /// <summary>
    /// Sets the shipping method display.
    /// </summary>
    private void SetShippingMethodDisplay() {
      if(!string.IsNullOrEmpty(order.ShippingMethod)) {
        lblShippingMethodDisplay.Text = order.ShippingMethod;
        cpeShippingMethodDisplay.Collapsed = false;
        acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1;
      }
    }

    /// <summary>
    /// Sets the coupon display.
    /// </summary>
    private void SetCouponDisplay() {
      if(order.DiscountAmount > 0) {
        lblCouponInformationDisplay.Text = StoreUtility.GetFormattedAmount(order.DiscountAmount, true);
        cpeCouponInformationDisplay.Collapsed = false;
        acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1;
      }
    }

    /// <summary>
    /// Sets the ship to address display.
    /// </summary>
    private void SetShipToAddressDisplay() {
      if(!string.IsNullOrEmpty(order.ShipToAddress)) {
        shippingAddressDisplay.Address = order.ShippingAddress;
        shippingAddress.SelectedAddress = order.ShippingAddress.AddressId.ToString();
        cpeShippingAddressDisplay.Collapsed = false;
        acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1;
        GetShippingRates();
      }
    }

    /// <summary>
    /// Sets the bill to address display.
    /// </summary>
    private void SetBillToAddressDisplay() {
      if(!string.IsNullOrEmpty(order.BillToAddress)) {
        billingAddressDisplay.Address = order.BillingAddress;
        billingAddress.SelectedAddress = order.BillingAddress.AddressId.ToString();
        cpeBillingAddressDisplay.Collapsed = false;
        acCheckout.SelectedIndex = acCheckout.SelectedIndex + 1;
      }
    }

    /// <summary>
    /// Gets the shipping rates.
    /// </summary>
    private void GetShippingRates() {
      ShippingOptionCollection shippingOptionCollection = OrderController.FetchShippingOptions(WebUtility.GetUserName());
      ListItem listItem;
      rblShippingOptions.Items.Clear();
      foreach(ShippingOption shippingOption in shippingOptionCollection) {
        listItem = new ListItem(string.Format("{0}: {1}", shippingOption.Service, StoreUtility.GetFormattedAmount(shippingOption.Rate, true)), shippingOption.Rate.ToString());
        rblShippingOptions.Items.Add(listItem);
      }
      if(order.ShippingAmount > 0) {
        ListItem selectedItem = rblShippingOptions.Items.FindByValue(order.ShippingAmount.ToString());
        if(selectedItem != null) {
          selectedItem.Selected = true;
        }
        else {
          rblShippingOptions.SelectedIndex = 0;
        }
      }
      else {
        rblShippingOptions.SelectedIndex = 0;
      }
    }

    /// <summary>
    /// Loads the expiration month drop down.
    /// </summary>
    private void LoadExpirationMonthDropDown() {
      if(ddlCreditCardExpirationMonth != null) {
        for(int i = 1;i <= 12;i++) {
          ddlCreditCardExpirationMonth.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
      }
    }

    /// <summary>
    /// Loads the expiration year drop down.
    /// </summary>
    private void LoadExpirationYearDropDown() {
      if(ddlCreditCardExpirationYear != null) {
        for(int i = DateTime.UtcNow.Year;i < DateTime.UtcNow.Year + 6;i++) {
          ddlCreditCardExpirationYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
      }
    }

    /// <summary>
    /// Sets the checkout properties.
    /// </summary>
    private void SetCheckoutProperties() {
      LocalizationUtility.AddCheckboxText(chkUseForShipping);
      LocalizationUtility.AddLabelText(lblBillingAddressTitle);
      LocalizationUtility.AddLabelText(lblShippingAddressTitle);
      LocalizationUtility.AddLabelText(lblShippingMethodTitle);
      LocalizationUtility.AddLabelText(lblCouponInformationTitle);
      LocalizationUtility.AddLabelText(lblCouponCode);
      LocalizationUtility.AddLabelText(lblPaymentInformationTitle);
      LocalizationUtility.AddLabelText(lblPaymentMethod);
      LocalizationUtility.AddLabelText(lblCreditCardNumber);
      LocalizationUtility.AddLabelText(lblCreditCardSecurityNumber);
      LocalizationUtility.AddLabelText(lblExpiration);
      LocalizationUtility.AddButtonText(btnProcessOrder);
      btnBillingAddress.Text = LocalizationUtility.GetText("lblContinue");
      btnShippingAddress.Text = LocalizationUtility.GetText("lblContinue");
      btnShippingMethod.Text = LocalizationUtility.GetText("lblContinue");
      btnPaymentMethod.Text = LocalizationUtility.GetText("lblContinue");
      btnCoupon.Text = LocalizationUtility.GetText("lblContinue");
    }

    #endregion

  }
}
